<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-form-item prop="time">
          <el-date-picker
            v-model="filters.time"
            type="daterange" value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="生效开始时间"
            end-placeholder="生效结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item prop="name">
          <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="今天" name="1"></el-tab-pane>
            <el-tab-pane label="昨天" name="2"></el-tab-pane>
            <el-tab-pane label="7天" name="3"></el-tab-pane>
            <el-tab-pane label="30天" name="4"></el-tab-pane>
          </el-tabs>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      @findPage="findPage"
      :showBatchDelete="false"
      :showDeleteOperation="false"
      :showEditOperation="false"
      :customLabel='"查看趋势图"'
      :showCustomOperation="true"
      :customLabel1='"栏目分析"'
      :showCustomOperation1="true"
      @handleCustom="handleCustom"
      @handleCustom1="handleCustom1"
      :showSelection="false"
      :operationWidth="300"
      ref="CyTable"
    ></cy-table>
    <div style="padding-top: 30px">
      <span v-model="cmsPageNameTxt">趋势图-{{cmsPageNameTxt}}</span>
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData"/>
      </el-row>
    </div>
    <el-dialog
      :title="operation"
      width="60%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
    >
      <template>
        <el-table
          :data="tableData"
          style="width: 100%"
          header-align="center"
          align="center"
          border
          :header-cell-style="{ 'color': '#FFF','background-color': '#2F4554'}"
        >
          <el-table-column
            prop="cmsPageName"
            label="栏目名称"
            sortable
            width="180">
          </el-table-column>
          <el-table-column
            prop="uv"
            label="总Uv"
            sortable
            width="180">
          </el-table-column>
          <el-table-column
            prop="pv"
            label="总Pv"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="address"
            label="成交订单数"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="address"
            label="成交销售额"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="address"
            label="转化率"
            sortable
          >
          </el-table-column>
        </el-table>
        <div class="toolbar" style="padding:10px;">
          <el-pagination
            layout="total, prev, pager, next, jumper,sizes"
            :current-page="pageRequest.pageNum"
            :page-size="pageRequest.pageSize"
            :total="3"
            style="float:right;"
            :page-sizes="[10, 20, 30, 40]"
          ></el-pagination>
        </div>
      </template>
    </el-dialog>
  </div>

</template>

<script>
  //import CyTable from "@/views/Core/CyTable";
  import LineChart from '@/components/Charts/LineMarker'
  import KtButton from "@/views/Core/KtButton"
  import {format} from "@/utils/datetime"
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog"
  import CyTable from "@/views/Core/StaticTable"

  const lineChartData = {
    newVisitis: {
      expectedData: [64, 120, 161],
      actualData: [105, 82, 91],
      actualData1: [10, 70, 80],
      actualData2: [123, 60, 60],
      actualData3: [60, 50, 50]
    }
  }
  export default {
    components: {
      CyTable,
      KtButton,
      TableColumnFilterDialog,
      LineChart
    },
    data() {
      return {
        tableData: [{
          cmsPageName: '单列大图-17',
          uv: '2',
          pv: '2'
        }, {
          cmsPageName: '单列多图-18',
          uv: '1',
          pv: '3'
        }, {
          cmsPageName: '单行滚动-14',
          uv: '13',
          pv: '15'
        }],
        lineChartData: lineChartData.newVisitis,
        activeName: "activeName",
        size: "small",
        filters: {
          time: "",
          name: "",
          status: "",
          res: {
            "total": 1,
            "code": "0000",
            "rows": [{
              "cmsPageId": "1911200007295609",
              "cmsPageName": "测试",
              "cmsTypeName": "",
              "uv": "64",
              "pv": "105",
              "payOrderNum": "10",
              "payOrderAmount": "123",
              "conversionRate": "4"
            }]
          }
        },
        columns: [
          {prop: "cmsPageId", label: "页面ID", minWidth: 120},
          {prop: "cmsPageName", label: "页面备注名称", minWidth: 120},
          {prop: "cmsTypeName", label: "页面类型", minWidth: 80},
          {prop: "uv", label: "总Uv", minWidth: 120},
          {prop: "pv", label: "总Pv", minWidth: 120},
          {prop: "payOrderNum", label: "成交订单数", minWidth: 120},
          {prop: "payOrderAmount", label: "成交销售额", minWidth: 120},
          {prop: "conversionRate", label: "转化率", minWidth: 120}
        ],
        filterColumns: [],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
        columns1: [
          {prop: "cmsPageName", label: "栏目名称", minWidth: 120},
          {prop: "uv", label: "总Uv", minWidth: 120},
          {prop: "pv", label: "总Pv", minWidth: 120},
          {prop: "payOrderNum", label: "成交订单数", minWidth: 120},
          {prop: "payOrderAmount", label: "成交销售额", minWidth: 120},
          {prop: "conversionRate", label: "转化率", minWidth: 120}
        ],
        operation: "", // true:新增, false:编辑
        editDialogVisible: false, // 新增编辑界面是否显示
        editDialogVisibleMatching: false,
        editLoading: false,
        dataFormRules: {
          replyContent: [{required: true, message: "回复内容", trigger: "blur"}]
        },
        // 新增编辑界面数据
        dataForm: {
          cmsPageName: "",
          status: "",
          radio: "",
          code: "OS190922110835123857",
          type: []
        },
        cmsPageNameTxt: "测试"
      };
    },
    methods: {
      // 获取分页数据
      findPage: function (data) {
        this.$refs.CyTable.findPageStaticState(this.filters);
      },
      //选择框
      selectionChange: function (params) {
        this.checked = params.selections
      },
      //批量操作
      handleEnable: function () {
        if (this.checked.length >= 1) {
          this.$message({message: "操作成功", type: "success"});
        } else {
          this.$message({message: '必须选中一条数据', type: 'error'})
        }
      },
      // 批量删除
      handleDelete: function (data) {
        if (data != null && data.params != null && data.params.length > 0) {
          let ids = data.params.map(item => item.id).toString();

          var params = {};
          params.t = "changeProduct";
          params.ids = ids;
          var this_ = this;
          this_.$message({message: "操作成功", type: "success"});
          this_.findPage(null);
        }
      },
      handleCustom: function (params) {
        this.lineChartData = {
          expectedData: [64, 120,33,22,32,110],
          actualData: [105, 82,13,55,12,33,110],
          actualData1: [10, 70,122,22,33,23,110],
          actualData2: [123, 60,15,33,33,122,110],
          actualData3: [60, 50,121,22,22,110,110]
        }
        this.cmsPageNameTxt = params.row.cmsPageName
      },
      handleCustom1: function (params) {
        this.operation = params.row.cmsPageName
        this.editDialogVisible = true;
      },
      // 新增匹配条件
      handleEditMatching: function (row) {
        this.dataFormMatching.matching = [row.variable, row.operator, row.name]
        this.editDialogVisibleMatching = true
      },
      // 编辑
      submitForm: function () {
        this.$refs.dataForm.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = Object.assign({}, this.dataForm);
              params.t = "changeProduct";
              var this_ = this;
              this.utils.request.editInfo(params, function (res) {
                if (res.code == "0000") {
                  this_.$message({message: "操作成功", type: "success"});

                  this_.$refs["dataForm"].resetFields();

                  this_.editDialogVisible = false;

                  this_.findPage(null);
                } else {
                  this_.$message({
                    message: "操作失败, " + res.msg,
                    type: "error"
                  });
                }
              });
            });
          }
        });
      },

      // 编辑匹配条件
      submitFormMatching: function () {
        this.$message({message: "操作成功", type: "success"});
        this.editDialogVisibleMatching = false;
      },
      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        return format(row[column.property]);
      },

      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
          this.filters.start_time = "";
          this.filters.end_time = "";
          this.findPage(null);
        }
      },

      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true);
      },
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns;
        this.$refs.tableColumnFilterDialog.setDialogVisible(false);
      },
      // 处理表格列过滤显示
      initColumns: function () {
        let temp = [];

        $.each(this.columns, function (key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      },
      //列表下载
      downloadExcel() {
        this.$confirm("确定下载列表文件?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let filename = "换货管理下载";
            this.$refs.CyTable.exportData(
              this.filters,
              this.filterColumns,
              filename
            );
          })
          .catch(() => {
          });
      },
      handleClick(tab, event) {
        if (tab.name == "1") {
          this.lineChartData = {
            expectedData: [100],
            actualData: [101],
            actualData1: [103],
            actualData2: [104],
            actualData3: [105]
          }
          this.filters.res = {
            "total": 1,
            "code": "0000",
            "rows": [{
              "cmsPageId": "1911200007295609",
              "cmsPageName": "测试",
              "cmsTypeName": "",
              "uv": "64",
              "pv": "105",
              "payOrderNum": "10",
              "payOrderAmount": "123",
              "conversionRate": "4"
            }]
          }
        } else if (tab.name == "2") {
          this.lineChartData = {
            expectedData: [64, 120],
            actualData: [105, 82],
            actualData1: [10, 70],
            actualData2: [123, 60],
            actualData3: [60, 50]
          }
          this.filters.res = {
            "total": 3,
            "code": "0000",
            "rows": [{
              "cmsPageId": "1911200007295609",
              "cmsPageName": "test",
              "cmsTypeName": "",
              "uv": "64",
              "pv": "105",
              "payOrderNum": "10",
              "payOrderAmount": "123",
              "conversionRate": "4"
            },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "jjc",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "105",
                "payOrderNum": "10",
                "payOrderAmount": "123",
                "conversionRate": "4"
              },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "bbc",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "105",
                "payOrderNum": "10",
                "payOrderAmount": "123",
                "conversionRate": "4"
              }]
          }
        } else if (tab.name == "3") {
          this.lineChartData = {
            expectedData: [64, 120,33,22,32],
            actualData: [105, 82,13,55,12,33],
            actualData1: [10, 70,122,22,33,23],
            actualData2: [123, 60,15,33,33,122],
            actualData3: [60, 50,121,22,22,110]
          }
          this.filters.res = {
            "total": 4,
            "code": "0000",
            "rows": [{
              "cmsPageId": "1911200007295609",
              "cmsPageName": "育学园商城0",
              "cmsTypeName": "",
              "uv": "64",
              "pv": "105",
              "payOrderNum": "10",
              "payOrderAmount": "123",
              "conversionRate": "4"
            },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "育学园商城1",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "105",
                "payOrderNum": "10",
                "payOrderAmount": "123",
                "conversionRate": "4"
              },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "育学园商城2",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "105",
                "payOrderNum": "10",
                "payOrderAmount": "123",
                "conversionRate": "4"
              },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "育学园商城3",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "321",
                "payOrderNum": "10",
                "payOrderAmount": "231",
                "conversionRate": "33"
              }]
          }

        } else {
          this.lineChartData = {
            expectedData: [64, 120,33,22,32,110],
            actualData: [105, 82,13,55,12,33,110],
            actualData1: [10, 70,122,22,33,23,110],
            actualData2: [123, 60,15,33,33,122,110],
            actualData3: [60, 50,121,22,22,110,110]
          }
          this.filters.res = {
            "total": 2,
            "code": "0000",
            "rows": [{
              "cmsPageId": "1911200007295609",
              "cmsPageName": "测试1",
              "cmsTypeName": "",
              "uv": "64",
              "pv": "105",
              "payOrderNum": "10",
              "payOrderAmount": "123",
              "conversionRate": "4"
            },
              {
                "cmsPageId": "1911200007295609",
                "cmsPageName": "测试2",
                "cmsTypeName": "",
                "uv": "64",
                "pv": "105",
                "payOrderNum": "10",
                "payOrderAmount": "123",
                "conversionRate": "4"
              }]
          }
        }
        this.findPage(this.filters);
      }
    },
    mounted() {
      this.initColumns()
    }
  };
</script>

<style scoped>
  .chart-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 84px);
  }
</style>
